﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using lib;
using XQ.Framework.model;
using XQ.Framework.core;
using XQ.Framework.common;

namespace XQ.Framework.html
{
    public class NavHtml
    {
        private static string getPartHtml(List<LinkModelBase> list, string select_flag)
        {
            try
            {
                if (list == null || list.Count == 0) { return ""; }
                StringBuilder html = new StringBuilder();
                list.ForEach(delegate(LinkModelBase model)
                {
                    if (model == null) { return; }
                    //判断是否选中
                    html.Append(string.Format("<li{0}>", model.Flag == select_flag ? " class='selected'" : string.Empty));
                    html.Append(HtmlHelper.getLinkHtml(model));
                    if (model.DropList != null && model.DropList.Count > 0)
                    {
                        html.Append(Com.getHtmlNotes("下拉开始"));
                        html.Append("<div class='drop_block'><ul class='drop_ul'>");
                        model.DropList.ForEach(delegate(LinkModelBase droplist)
                        {
                            if (droplist == null) { return; }
                            html.Append(string.Format("<li>{0}</li>", HtmlHelper.getLinkHtml(droplist)));
                        });
                        html.Append("</ul></div>");
                        html.Append(Com.getHtmlNotes("下拉结束"));
                    }
                    html.Append("</li>");
                });
                return html.ToString();
            }
            catch (Exception e)
            {
                return string.Empty;
            }
        }





        public static string CreatMenuHtml(Dictionary<string, List<LinkModelBase>> data, string select_flag)
        {
            return CreatMenuHtml(data, "wj_nav black_nav", select_flag);
        }
        public static string CreatMenuHtml(Dictionary<string, List<LinkModelBase>> data, string mclass, string select_flag)
        {
            try
            {
                if (data == null) { return string.Empty; }
                List<LinkModelBase> leftData = data.ContainsKey("left") ? data["left"] : null;
                List<LinkModelBase> rightData = data.ContainsKey("right") ? data["right"] : null;
                //string html = "<div class='" + mclass + "'>";
                StringBuilder html = new StringBuilder();
                html.Append(string.Format("<div class='{0}'>", mclass));
                //获取左边
                html.Append("<ul class='left_nav'>");
                html.Append(getPartHtml(leftData, select_flag));
                html.Append("</ul>");
                //获取右边
                html.Append("<ul class='right_nav'>");
                html.Append(getPartHtml(rightData, select_flag));
                html.Append("</ul>");

                html.Append("</div>");
                return html.ToString();
            }
            catch (Exception e)
            {
                return string.Empty;
            }
        }
    }
}
